<template>
	<view class="content">
		<view class="top">
			<view class="money">
				{{withdraw.money}}
				<span>{{$t('deposit.money')}}</span>
			</view>
			<view class="button" @click="convertTo">{{$t('deposit.button1')}}</view>
		</view>
		<view class="text">
			<view class="title">
				{{$t('deposit.title')}}
			</view>
			<view class="right">
			</view>
		</view>
		<radio-group @change="changeNum">
			<view class="list">
				<view class="item" v-for="(item, index) in withdraw.rule" :key="index">
					<view class="left">
						{{ item}}
						<span>{{$t('deposit.money')}}</span>
					</view>
					<radio :value="item+''" :checked="money == item" color="#F75581" />
				</view>
			</view>
		</radio-group>
		<view class="bottom">
			<view class="button" @click="saveClick">
				{{$t('deposit.button2')}}
			</view>
		</view>
		<popup-convert ref="convert" @change="change"></popup-convert>
	</view>
</template>

<script>
	import PopupConvert from '@/components/popup-convert/index.vue'
	import util from '../../../utils/util'
	export default {
		components: {
			PopupConvert
		},
		data() {
			return {
				withdraw: {},
				money: ''
			}
		},
		onLoad() {
			this.withdrawRule()
			util.setNavTitle()
		},
		methods: {
			withdrawRule() {
				uni.request({
					url: this.configs.webUrl + '/api/user_coin/withdrawRule',
					data: {
						token: uni.getStorageSync('userinfo').token
					},
					success: res => {
						console.log('withdrawRule', res);
						this.withdraw = res.data.data
						if (this.withdraw.is_withdraw_min == 1) {
							this.withdraw.rule.splice(0, 1)
						}
					}
				})
			},
			changeNum(e) {
				this.money = e.detail.value
			},
			convertTo() {
				this.$refs.convert.open()
			},
			change() {
				this.withdrawRule()
			},
			saveClick() {
				uni.request({
					url: this.configs.webUrl + '/api/user_coin/withdrawMoney',
					data: {
						token: uni.getStorageSync('userinfo').token,
						money: this.money
					},
					success: res => {
						console.log('withdrawMoney', res);
						if (res.data.code == 1) {
							this.withdrawRule()
						}
						util.toast(res.data.msg)
					}
				})
				// uni.navigateTo({
				// 	url: '/pages/client/wallet/definite-withdrawal'
				// })
			}
		}
	}
</script>

<style lang="scss" scoped>
	.content {
		padding: 20rpx;

		.top {
			border-radius: 20rpx;
			padding: 0 20rpx;
			background: linear-gradient(90deg, #F75581 0%, #C860FF 100%);
			height: 182rpx;
			display: flex;
			align-items: center;
			justify-content: space-between;

			.money {
				font-size: 72rpx;
				font-family: PingFang SC, PingFang SC;
				font-weight: 600;
				color: #FFFFFF;

				span {
					font-size: 32rpx;
				}
			}

			.button {
				background: #fff;
				padding: 5rpx 10rpx;
				border-radius: 20rpx;
				font-size: 24rpx;
				font-family: PingFang SC, PingFang SC;
				font-weight: 400;
				color: #F75581;
			}
		}

		.text {
			display: flex;
			align-items: center;
			justify-content: space-between;
			margin: 20rpx 0;

			.title {
				font-size: 32rpx;
				font-family: Inter, Inter;
				font-weight: 400;
				color: #000000;
			}

			.right {
				font-size: 28rpx;
				font-family: Inter, Inter;
				font-weight: 400;
				color: #F75581;
			}
		}

		.list {
			display: flex;
			flex-wrap: wrap;
			align-items: center;
			justify-content: space-between;


			.item {
				width: 48%;
				background: #fff;
				border-radius: 20rpx;
				box-shadow: 0rpx 4rpx 8rpx 2rpx rgba(0, 0, 0, 0.08);
				margin-bottom: 20rpx;
				height: 98rpx;
				display: flex;
				align-items: center;
				justify-content: space-between;
				padding: 0 20rpx;

				.left {
					font-size: 32rpx;
					font-family: PingFang SC, PingFang SC;
					font-weight: 600;
					color: #2F3438;

					span {
						font-size: 20rpx;
					}
				}
			}
		}

		.bottom {
			position: absolute;
			bottom: 0;
			left: 0;
			width: 100%;
			background: #fff;
			padding: 10rpx 40rpx 50rpx;

			.button {
				height: 84rpx;
				display: flex;
				align-items: center;
				justify-content: center;
				border-radius: 60rpx;
				background: linear-gradient(90deg, #F75581 0%, #C860FF 100%);
				font-size: 32rpx;
				font-family: PingFang SC, PingFang SC;
				font-weight: 600;
				color: #FFFFFF;
			}
		}
	}
</style>